home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 80 / CD Actual 80 Julio-Agosto 2003.iso / Linux / LinuxGazette / lg / issue15 / source / example-3a.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-14  |  4.2 KB  |  139 lines

  1. #include <stdio.h>
  2. #include <ri.h>
  3.  
  4. /*
  5.  * BMRT Introduction - Michael J. Hammel
  6.  * Example 1b - a sphere over a plane
  7.  */
  8. main()
  9. {
  10.    /* The angle of the field of view of this image */
  11.    RtFloat fov = 35.0;
  12.  
  13.    /* The color we'll use for the sphere */
  14.    RtColor blue = { 0.2,0.3,0.9 };
  15.  
  16.    /* The color we'll use for the plane under the sphere */
  17.    RtColor gray = { 0.9, 0.9, 0.9 };
  18.  
  19.    /* The intensity level of the distant light */
  20.    RtFloat intensity = 1.0;
  21.  
  22.    /*
  23.     * Coordinates for the distant light.
  24.     */
  25.    RtPoint from = {0.0, 10.5, -100.0};
  26.    RtPoint to = {0.0, 0.0, 0.0};
  27.    RtPoint from2 = {0.0, 0.0, 2.0};
  28.    RtPoint to2 = {0.0, -1.0, 3.5};
  29.  
  30.    /* The coordinates of the corners of our plane */
  31.    RtPoint points[4] = { 
  32.          -3.0, 0.0, 0.0,
  33.           3.0, 0.0, 0.0,  
  34.           3.0, 3.0, 0.0,
  35.          -3.0, 3.0, 0.0
  36.          };
  37.  
  38.    /*
  39.     * RI_NULL means send RIB output to standard out; this could be 
  40.     * changed to a filename to force the RIB to a specific file.  You can
  41.     * also specify the name of the one of the BMRT renderers which will
  42.     * cause the output to be piped directly to that renderer.
  43.     */
  44.    RiBegin(RI_NULL);
  45.  
  46.       /*
  47.        * The filename of the rendered image is specfified in the RiDisplay
  48.        * command.  This is not where the RIB output goes, this is where
  49.        * the output from the renderer goes.
  50.        */
  51.       RiDisplay ("example-2a.tif", RI_FILE, RI_RGB, RI_NULL);
  52.  
  53.       /*
  54.        * Image size - the "1" is the ratio of width to height for pixels.
  55.        * Unless you're using non-square pixels this should always be 1.
  56.        */
  57.       RiFormat (480, 360, 1);
  58.  
  59.       /*
  60.        * Set the samples per pixel to be 1 in each direction.
  61.        */
  62.       RiPixelSamples ( 1, 1 );
  63.  
  64.       /*
  65.        * Perspective views give a more realistic sense of depth to
  66.        * the image.  
  67.        */
  68.       RiProjection ( RI_PERSPECTIVE, RI_FOV, (RtPointer)&fov, RI_NULL );
  69.  
  70.       /*
  71.        * Set our initial position for World objects.  Basically this 
  72.          * is just setting our initial camera position to 8 units in 
  73.          * the positive Z direction.  Any changes we would make to the
  74.          * cameras postion would be relative to this.
  75.        */
  76.       RiTranslate (0, 0, 8);
  77.  
  78.       /*
  79.        * Now we start to define the objects in our scene.
  80.          * All our rendering options are frozen inside the World commands.
  81.        */
  82.       RiWorldBegin();
  83.  
  84.          /*
  85.           * Set up a distant light source.  Distant lights have parallel
  86.              * rays which follow a line parallel to the line defined by
  87.              * "from" and "to" below.
  88.           */
  89.          RiLightSource(RI_DISTANTLIGHT, RI_INTENSITY, &intensity, 
  90.                RI_FROM, (RtPointer)from, RI_TO, (RtPointer)to, RI_NULL);
  91.  
  92.          /*
  93.           * Each object has its own set of attributes.  Putting them
  94.           * inside the Attribute commands prevents us from accidently
  95.           * forgetting to reset the attributes, such as a colors,
  96.           * for a later object.
  97.           */
  98.          RiAttributeBegin();
  99.  
  100.             /*
  101.              * We need to set the surface texture of the sphere first.  Here
  102.              * we use a simple matte surface shader which is provided
  103.              * in the BMRT distribution.  The surface will have a blue
  104.                  * color.
  105.              */
  106.             RiColor(blue);
  107.             RiSurface("matte", RI_NULL);
  108.  
  109.             /*
  110.              * Next we define our sphere.  We'll move it up a little from
  111.                  * the XZ plane.
  112.              */
  113.             RiTranslate ( 0, 0.75, 0.0 );
  114.             RiSphere(0.8,-0.8, 0.8, 360.0, RI_NULL);
  115.  
  116.          RiAttributeEnd();
  117.  
  118.          RiLightSource(RI_SPOTLIGHT, RI_INTENSITY, &intensity, 
  119.                RI_FROM, (RtPointer)from2, RI_TO, (RtPointer)to2, RI_NULL);
  120.  
  121.          /*
  122.           * Now a shiny, metal plane below the sphere.
  123.           */
  124.          RiAttributeBegin();
  125.             RiColor(gray);
  126.             RiSurface("matte", RI_NULL);
  127.             RiTranslate ( 0, -1.0, 2.0 );
  128.             RiRotate ( 80, 1, 0, 0 );
  129.             RiPolygon(4, RI_P, (RtPointer)points, RI_NULL);
  130.          RiAttributeEnd();
  131.  
  132.         /*
  133.          * Don't forget:  RiWorldEnd() causes the current scene to be 
  134.          * written to the output file (or standard out if no file is
  135.          * defined).
  136.          */
  137.       RiWorldEnd();
  138. }
  139.